package com.xbongbong.pro.statistic.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.pro.domain.dao.DataWarningDao;
import com.xbongbong.pro.domain.entity.DataWarningEntity;
import com.xbongbong.pro.statistic.model.DataWarningModel;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName DataWarningModelImpl
 * @Description 数据预警
 * @Author mengna.Deng
 * @Date 2021/4/15 19:33
 * @Version 1.0
 */
@Service("dataWarningModel")
public class DataWarningModelImpl implements DataWarningModel {

    @Resource
    private DataWarningDao dataWarningDao;

    @Override
    public Integer insert(DataWarningEntity entity){
        return dataWarningDao.insert(entity);
    }

    @Override
    public Integer update(DataWarningEntity entity){
        return dataWarningDao.update(entity);
    }

    @Override
    public List findEntitys(Map<String, Object> param) {
        return dataWarningDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return dataWarningDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer save(DataWarningEntity entity){

        if(entity.getId() == null || entity.getId().equals(0L)) {
            return dataWarningDao.insert(entity);
        }
        return dataWarningDao.update(entity);
    }

    @Override
    public Integer deleteByKey(Long key, String corpid) {return dataWarningDao.deleteByKey(key, corpid);}

    @Override
    public void insertBatch(List<DataWarningEntity> entityList) {
        dataWarningDao.insertBatch(entityList);
    }

    @Override
    public DataWarningEntity getByKey(Long key, String corpid) {
        return dataWarningDao.getByKey(key, corpid);
    }

    @Override
    public List<String> findCorps(Map<String, Object> param) {
        return dataWarningDao.findCorps(param);
    }

    @Override
    public Integer getCorpsCount() {
        return dataWarningDao.getCorpsCount();
    }

    @Override
    public Integer getEnableCount(String corpid) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put(StringConstant.CORPID, corpid);
        param.put("enable", BasicConstant.IS_USE);
        param.put("del", DelEnum.NORMAL.getDel());
        return getEntitysCount(param);
    }

    @Override
    public int getCountByChartId(Long chartId,Integer enable ) {
        return dataWarningDao.getCountByChartId(chartId,enable);
    }

    @Override
    public void updateBatch(List<DataWarningEntity> entityList, String corpid) {
        dataWarningDao.updateBatch(entityList,corpid);
    }

    @Override
    public List<DataWarningEntity> queryByChartId(String corpid, Long chartId) {
        return dataWarningDao.queryByChartId(corpid,chartId);
    }

    @Override
    public List<Long> findDwIds(Map<String, Object> param) {
        return dataWarningDao.findDwIds(param);
    }

    @Override
    public void deleteBatch(String corpid, List<Long> chartIdIn) {
        dataWarningDao.deleteBatch(corpid,chartIdIn);
    }
}
